package com.tianhui.consignortwofei.mvp.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;

import com.fgs.common.CommonFragment;
import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonView;
import com.fgs.common.adapter.FragmentPagerAdapter;
import com.fgs.common.widget.CustomViewPager;
import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.base.BaseActivity;
import com.tianhui.consignortwofei.mvp.ui.fragment.OrderListFragment;
import com.tianhui.consignortwofei.pattern.orderStatus.status.impl.DispatchStatus;
import com.tianhui.consignortwofei.pattern.orderStatus.status.impl.DispatchStatusDingJin;
import com.tianhui.consignortwofei.role.RoleController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;

/**
 * @author fgs
 * @date 2020/8/31
 * @description
 **/
public class DiaoDuOrderListActivity extends BaseActivity {
    @BindView(R.id.activity_order_list_viewPager)
    CustomViewPager mViewPager;
    @BindView(R.id.activity_order_list_slidingTabLayout)
    SlidingTabLayout mTabLayout;
    @BindView(R.id.activity_order_list_TabFrameLayout)
    FrameLayout mTabFrameLayout;
    private List<CommonFragment> mFragmentList = new ArrayList<>();
    private FragmentPagerAdapter mPagerAdapter;

    @Override
    public String getToolbarTitle() {
        return "货源管理";
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_order_list;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public void init() {


        mPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager());
        mPagerAdapter.setFragments(createFragmentList());
        mViewPager.setCanScroll(false);
        mViewPager.setHasEffect(false);
        mViewPager.setOffscreenPageLimit(mFragmentList.size());
        mViewPager.setAdapter(mPagerAdapter);

        mPagerAdapter.setTabTitles(Arrays.asList(getResources().getStringArray(R.array.array_order_diaodu_tab)));
        mTabLayout.setViewPager(mViewPager);


        Bundle bundle = getIntent().getExtras();
        int index = 0;
//        if (bundle != null && !bundle.isEmpty()) {
//            index = bundle.getInt(KeyValue.KEY_TYPE);
//            if (index == OrderType.TYPE_SOURCE) {
                setCurrentItem(0);
//                getToolbarStatus().setTitle("货源管理");
//            }
////            else if (index == OrderType.TYPE_INQUIRY) {
////                setCurrentItem(1);
////                getToolbarStatus().setTitle("询价管理");
////            }
//            else if (index == OrderType.TYPE_DISPATCH) {
//                setCurrentItem(1);
                getToolbarStatus().setTitle("调度管理");
//            }
//        }







        boolean isShowOrderTypeTabLayout = RoleController.getInstance().isShowOrderTypeTabLayout();
        if (isShowOrderTypeTabLayout) {
            mTabFrameLayout.setVisibility(View.VISIBLE);
        } else {
            mTabFrameLayout.setVisibility(View.GONE);
        }


        initListener();
    }

    @Override
    public CommonFragment createFragment() {
        return null;
    }

    private void initListener() {

        mTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                switch (position) {
                    case 0:
                        mViewPager.setCurrentItem(0);
//                        getToolbarStatus().setTitle("货源管理");

                        break;
//                    case 1:
//                        mViewPager.setCurrentItem(1);
//                        getToolbarStatus().setTitle("询价管理");
//                        break;
                    case 1:
                        mViewPager.setCurrentItem(2);
//                        getToolbarStatus().setTitle("调度管理");
                        break;
                }
            }

            @Override
            public void onTabReselect(int position) {

            }
        });

    }

    private List<CommonFragment> createFragmentList() {
//        mFragmentList.add(OrderListFragment.newInstance(new SourceStatus()));//货源
//        mFragmentList.add(OrderListFragment.newInstance(new InquirySourceStatus()));

        mFragmentList.add(OrderListFragment.newInstance(new DispatchStatus()));
        mFragmentList.add(OrderListFragment.newInstance(new DispatchStatusDingJin()));//有定金
        return mFragmentList;
    }

    private void setCurrentItem(int item) {
        mViewPager.setCurrentItem(item);
    }

//    @Override
//    protected void onNewIntent(Intent intent) {
//        super.onNewIntent(intent);
//        Bundle bundle  = intent.getExtras();
//        if (bundle!= null && !bundle.isEmpty()){
//            int index = bundle.getInt(KeyValue.KEY_VALUE);
//            setCurrentItem(index);
//        }
//    }
}
